      SUBROUTINE E01DAP(NXDATA,XDATA,X,JINTVL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     A DASL routine, unmodified except for name.
C
C     **********************************************************
C
C     D A S L  -  DATA APPROXIMATION SUBROUTINE LIBRARY
C
C     SUBROUTINE INTVAL    DETERMINE THE INTERVAL INDEX
C     =================    JINTVL  ASSOCIATED WITH  X
C
C     CREATED 08 05 78.  UPDATED 21 06 82.  RELEASE 00/05
C
C     AUTHORS ... MAURICE G. COX, PAULINE E. M. CURTIS AND
C                 J. GEOFFREY HAYES
C     NATIONAL PHYSICAL LABORATORY, TEDDINGTON,
C     MIDDLESEX  TW11 0LW, ENGLAND
C
C     (C)  CROWN COPYRIGHT 1978-1982
C
C     **********************************************************
C
C     INTVAL.  DETERMINES THE INTERVAL INDEX  JINTVL  WITH
C     THE PROPERTY THAT
C        XDATA(JINTVL) .LE. X .LT. XDATA(JINTVL + 1)
C
C     INPUT PARAMETERS
C        NXDATA   NUMBER OF ABSCISSA VALUES
C        XDATA    ABSCISSA VALUES
C        X        ABSCISSA VALUE
C
C     INPUT/OUTPUT  PARAMETER
C        JINTVL   INTERVAL INDEX ASSOCIATED WITH  X
C
C     ----------------------------------------------------------
C
C     .. Scalar Arguments ..
      DOUBLE PRECISION  X
      INTEGER           JINTVL, NXDATA
C     .. Array Arguments ..
      DOUBLE PRECISION  XDATA(NXDATA)
C     .. Local Scalars ..
      INTEGER           I, JMAX, JMIN, JTEMP, MXDATA, POWER
C     .. External Subroutines ..
      EXTERNAL          E01DAU
C     .. Executable Statements ..
C
C     INITIALIZE MAXIMUM AND MINIMUM VALUES FOR J
C
      JMAX = NXDATA
      JMIN = 1
      IF (X.GE.XDATA(JINTVL)) GO TO 60
C
C     HERE IF  X  IS LESS THAN  XDATA(JINTVL)  AND
C     GREATER THAN  XDATA(1)
C
      DO 20 I = 1, NXDATA
         IF (I.EQ.1) POWER = 1
         IF (I.GT.1) POWER = 2*POWER
         JTEMP = JINTVL - POWER
C
C        ENSURE THAT THE CURRENT VALUE FOR  JTEMP  IS
C        NOT OUT OF RANGE.
C
         IF (JTEMP.LT.1) JTEMP = 1
C
C        IF  X  IS LESS THAN THE CURRENT VALUE FOR
C        XDATA(JTEMP)  THEN REDUCE JTEMP
C
         IF (X.GE.XDATA(JTEMP)) GO TO 40
   20 CONTINUE
C
C     IT IS KNOWN THAT  X  IS NOT LESS THAN  XDATA(JTEMP)
C     AND THAT  X  IS LESS THAN  XDATA(JTEMP + 2**(R - 1))
C
   40 JMIN = JTEMP
      JMAX = JINTVL
      IF (POWER.GT.1) JMAX = JMIN + POWER/2
      GO TO 120
C
C     HERE IF  X  IS NOT LESS THAN  XDATA(JINTVL)  AND IS
C     LESS THAN  XDATA(NXDATA)
C
   60 DO 80 I = 1, NXDATA
         IF (I.EQ.1) POWER = 1
         IF (I.GT.1) POWER = 2*POWER
         JTEMP = JINTVL + POWER
C
C        ENSURE THAT THE CURRENT VALUE FOR  JTEMP  IS
C        NOT OUT OF RANGE.
C
         IF (JTEMP.GT.NXDATA) JTEMP = NXDATA
         IF (X.LT.XDATA(JTEMP)) GO TO 100
   80 CONTINUE
C
C     IT IS KNOWN THAT  X  IS NOT GREATER THAN  XDATA(JTEMP)
C     AND THAT  X  IS GREATER THAN
C     XDATA(JTEMP - 2**(R - 1))
C
  100 JMAX = JTEMP
      JMIN = JINTVL
      IF (POWER.GT.1) JMIN = JTEMP - POWER/2
C
C     BINARY SEARCH REQUIRES  MXDATA  KNOTS
C
  120 MXDATA = JMAX - JMIN + 1
C
C     LOOK FOR THE INTERVAL  JTEMP  CONTAINING THE GIVEN  X.
C     IT IS KNOWN THAT  XDATA(JMIN) .LE. X .LT. XDATA(JMAX).
C
      CALL E01DAU(MXDATA,XDATA(JMIN),X,JTEMP)
C
C     THE ROUTINE  E01DAU  GIVES A RELATIVE INTERVAL INDEX
C     BETWEEN  1  AND  JMAX - JMIN.  DETERMINE THE
C     ACTUAL INTERVAL INDEX.
C
      JINTVL = JTEMP + JMIN - 1
      RETURN
C
C     END E01DAP
C
      END
